using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using SpoonCore2.Client;
using System.IO;

namespace SpoonCore2.Service.Lookup
{
	public abstract class AbstractLookupItem : ILookupItem
	{
		private static readonly SHA1Managed _sha1 = new SHA1Managed();

		private SpoonIdentifier _id = new SpoonIdentifier();
		private int _version = 0;

		public SpoonIdentifier LookupId
		{
			get { return _id; }
			set { _id = value; }
		}
		public int Version
		{
			get { return _version; }
			set { _version = value; }
		}

		public abstract SpoonIdentifier TypeId { get;}
		public abstract void GetBytes(BinaryWriter writer);
		public abstract void SetBytes(BinaryReader reader);

		public static byte[] ComputeHash(ILookupItem item)
		{
			MemoryStream stream = new MemoryStream();
			BinaryWriter bw = new BinaryWriter(stream);
			item.GetBytes(bw);

			return _sha1.ComputeHash(stream);
		}
	}
}